<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>发布微博</title>
    <!-- 引入Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <!-- 引入Vue.js -->
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
    <!-- 引入Axios -->
    <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
</head>
<body>
<div id="app" class="flex items-center justify-center min-h-screen bg-gradient-to-r from-green-400 to-blue-500">
    <div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-md transition-transform transform hover:scale-105">
        <h2 class="text-3xl font-bold text-center mb-6 text-gray-800">发布微博</h2>
        <form @submit.prevent="insert">
            <textarea v-model="weibo.content" class="w-full p-4 border border-gray-300 rounded-lg mb-4 focus:outline-none focus:ring-2 focus:ring-blue-400 transition duration-200 ease-in-out" placeholder="说点儿啥..." required rows="4"></textarea>
            <button type="submit" class="w-full bg-blue-500 text-white py-2 px-4 rounded-lg hover:bg-blue-600 transition-colors duration-200 shadow-md hover:shadow-lg">发微博</button>
            <p v-if="errorMessage" class="text-red-500 mt-2 text-center">{{ errorMessage }}</p>
        </form>
        <p class="mt-4 text-gray-500 text-sm text-center">发布微博后，您将被重定向到首页。</p>
        <div class="mt-6 text-center">
            <p class="text-sm text-gray-600">© 2024 微博平台. 保留所有权利</p>
        </div>
    </div>
</div>
<script>
    const app = new Vue({
        el: '#app',
        data() {
            return {
                weibo: { content: '' },
                errorMessage: ''
            };
        },
        methods: {
            async insert() {
                try {
                    const response = await axios.post('/v1/weibo/insert', this.weibo);
                    if (response.data === 1) {
                        window.location.href = '/'; // 回到首页
                    } else {
                        this.errorMessage = '请先登录!';
                        setTimeout(() => {
                            window.location.href = '/login.html';
                        }, 2000); // 2秒后跳转到登录页
                    }
                } catch (error) {
                    console.error('Error posting weibo:', error);
                    this.errorMessage = '网络错误，请稍后再试。';
                }
            }
        }
    });
</script>
</body>
</html>